<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>管理页面</title>
    <script src="/static/js/jquery-3.2.1.min.js"></script>
    <!-- Site CSS -->
    <link href="/static/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<ol class="breadcrumb">
    <li class="active"><a href="{:url('backend/Index/index')}">首页</a></li>
    <li class="active">文章管理</li>
    <li class="active">文章列表</li>
</ol>


<div class="panel panel-default">
    <div class="panel-heading">
        搜索
    </div>
    <div class="panel-body">
        <form id="searchForm" method="post" class="form-inline" action="{:url('backend/Article/index')}">
            <div class="form-group">
                <label for="search_name">名称</label>
                <input type="text" class="form-control" name="search_name" value="{$map.search_name ? $map.search_name : ''}" id="search_name" placeholder="请输入文章名称">
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-default">开始搜索</button>
            </div>
        </form>
    </div>
</div>
<!--新增按钮-->
<a href="{:url('backend/article/read')}" class="btn btn-sm btn-primary">新增</a>

<div class="table-responsive">

    <table class="table table-striped ">
        <thead>
        <tr>
            <td>编号</td>
            <td>所属栏目名</td>
            <td>文章标题</td>
            <td>文章创建时间</td>
            <td>文章修改时间</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody id="lists">

        {volist name="lists" id="vo"}
        <tr id="list-{$vo.article_id}">
            <td>{$vo.article_id}</td>
            <td>{$vo.category['category_name']}</td>
            <td>{$vo.article_name}</td>
            <td>{$vo.create_time}</td>
            <td>{$vo.update_time}</td>
            <td>
                <input type="hidden" id="">
                <button type="button" class="btn btn-sm btn-danger" data-id="{$vo.article_id}" data-name="{$vo.article_name}" data-type="del">删除</button>
                <a href="{:url('backend/Article/read')}?article_id={$vo.article_id}" class="btn btn-sm btn-primary">修改</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<div class="pagenation">
    {$page}
</div>

<script type="text/javascript">
    //删除按钮
    $("#lists button").click(function () {
        var article_name = $(this).attr('data-name');
        var article_id = $(this).attr('data-id');
        var type = $(this).attr('data-type');
        if (type === 'del')
        {
            if(confirm("确定删除栏目名为"+article_name+"吗？")){
                $.ajax({
                    url: "{:url('backend/article/delete')}",
                    method: "POST",
                    data: {"article_id": article_id},
                    dataType: "json",
                    success: function (res) {
                        if (res.status === 0) {
                            alert(res.msg);
                            return false;
                        }
                        $("#list-" + article_id).remove();
                    }
                });
            }
        }
        else if (type === 'update')
        {
            $.ajax({
                url: "{:url('backend/article/read')}",
                method: "POST",
                data: {"article_id": article_id},
                dataType: "json",
                success: function (res) {
                    if (res.status === 0) {
                        alert(res.msg);
                        return false;
                    }
                    var article = res.data;
                    $("#select option").each(function() {
                        if($(this).val() == article.category_id){
                            $(this).prop('selected',true);
                        }
                    });
                    $("#article_name").val(article.article_name);
                    $("#container").val(article.content);
                    $("#article_id").val(article.article_id);
                }
            });
        }
    });
</script>
</body>
</html>